package com.digitalchina.trade.controller;

import com.digitalchina.trade.service.impl.AccountServiceImpl;
import com.digitalchina.trade.utils.MailUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.mail.MessagingException;
import javax.servlet.http.HttpServletRequest;

/**
 * @auther xiaoming
 * @date 2021年06月13日16:48
 */
@RestController
public class AccountController {
    @Autowired
    private AccountServiceImpl accountService;
    @RequestMapping(value = "/register")
    public ModelAndView register() {
        ModelAndView mv=new ModelAndView();
        mv.setViewName("register");
        return mv;
    }
//    @PostMapping(value = "/saveAccount")
//    public ModelAndView saveAccount(String account_name,String account_pwd,String account_upwd,
//                               String  account_cradNum,String account_email,String account_phoneNum){
//        ModelAndView mv=new ModelAndView();
//        mv.addObject("msg", accountService.saveAccount(account_name,account_pwd,account_upwd, account_cradNum,account_email,account_phoneNum));
//        mv.setViewName("ok");
//        return mv;
//    }
    @PostMapping(value = "/saveAccount")
    public ModelAndView saveAccount(String account_name, String account_pwd, String account_upwd,
                              String  account_cradNum, String account_email, String account_phoneNum, HttpServletRequest request){
        ModelAndView mv=new ModelAndView();
        String msg =  accountService.saveAccount(account_name,account_pwd,account_upwd, account_cradNum,account_email,account_phoneNum);
        request.getSession().setAttribute("msg",msg);
        mv.setViewName("register");
        return mv;
        }

//    @RequestMapping(value = "sendemail")
//    public void sendEmail(String account_email){
//        String msg = "注册";
//        String emailaccount = "123456";
//        try {
//            MailUtils.sendMail(account_email,msg,emailaccount);
//        } catch (MessagingException e) {
//            e.printStackTrace();
//        }
//    }

}
